From c86032d11851b165eb6f92ae799cc652fae1b513 Mon Sep 17 00:00:00 2001 From: "cl349@firebug.cl.cam.ac.uk" Date: Tue, 26 Jul 2005 15:21:00 +0000 Subject: [PATCH] Make testing more reliable: wait for event after async so we know child has done command Signed-off-by: Rusty Russel Signed-off-by: Christian Limpach --- tools/xenstore/testsuite/13watch-ack.sh | 2 +- tools/xenstore/xs_test.c | 39 +++++++++++++++++++++++-- 2 files changed, 38 insertions(+), 3 deletions(-) diff --git a/tools/xenstore/testsuite/13watch-ack.sh b/tools/xenstore/testsuite/13watch-ack.sh index 30125fa6af..454ef6da56 100644 --- a/tools/xenstore/testsuite/13watch-ack.sh +++ b/tools/xenstore/testsuite/13watch-ack.sh @@ -16,8 +16,8 @@ echo mkdir /test/3 | ./xs_test 1 watch /test/2 token2 0 1 watch /test/3 token3 0 2 async write /test/2 create contents2 -1 waitwatch 3 async write /test/1 create contents1 4 async write /test/3 create contents3 +1 waitwatch 1 ackwatch token2 1 close' | ./xs_test 2>&1`" = "1:/test/2:token2" ] diff --git a/tools/xenstore/xs_test.c b/tools/xenstore/xs_test.c index 71719365dd..b7b1ee01ed 100644 --- a/tools/xenstore/xs_test.c +++ b/tools/xenstore/xs_test.c @@ -406,6 +406,35 @@ static void do_ackwatch(unsigned int handle, const char *token) failed(handle); } +static bool wait_for_input(unsigned int handle) +{ + unsigned int i; + for (i = 0; i < ARRAY_SIZE(handles); i++) { + int fd; + + if (!handles[i] || i == handle) + continue; + + fd = xs_fileno(handles[i]); + if (fd == -2) { + unsigned int avail; + get_input_chunk(in, in->buf, &avail); + if (avail != 0) + return true; + } else { + struct timeval tv = {.tv_sec = 0, .tv_usec = 0 }; + fd_set set; + + FD_ZERO(&set); + FD_SET(fd, &set); + if (select(fd+1, &set, NULL, NULL,&tv)) + return true; + } + } + return false; +} + + /* Async wait for watch on handle */ static void do_command(unsigned int default_handle, char *line); static void do_async(unsigned int handle, char *line) @@ -413,8 +442,14 @@ static void do_async(unsigned int handle, char *line) int child; unsigned int i; children++; - if ((child = fork()) != 0) + if ((child = fork()) != 0) { + /* Wait until *something* happens, which indicates + * child has created an event. V. sloppy, but we can't + * select on fake domain connections. + */ + while (!wait_for_input(handle)); return; + } /* Don't keep other handles open in parent. */ for (i = 0; i < ARRAY_SIZE(handles); i++) { @@ -632,7 +667,7 @@ static void do_command(unsigned int default_handle, char *line) command = arg(line, 0); if (timeout) - alarm(5); + alarm(1); if (streq(command, "dir")) do_dir(handle, arg(line, 1)); -- 2.30.2